More problems from the Colombian National Contest 2010. Only two to go.
[and.git] / 305 - Joseph / 2robado305.cpp
blob0ca039cbb2a65a04fcc0b05a38c938255860d1b1
1 /* Código robado del foro DESPUÉS de haberlo resuelto yo.
3 http://acm.uva.es/board/viewtopic.php?t=8570
5 */
9 #include <iostream>
10 using namespace std;
12 int f(int k)
14 int m, n, p, r;
16 for (n = 2 * k, m = 2;; m++) {
17 for (p = 0, r = n; r > k; r--)
18 if ((p = (p + m - 1) % r) < k) break;
19 if (r == k) return m;
23 int main (void)
25 int k;
26 while ((cin>>k)&&k)
27 cout << f(k) << endl;
28 return 0;